package com.itheima.controller;


import com.itheima.common.R;
import com.itheima.domain.Product;
import com.itheima.domain.ProductParam;
import com.itheima.manager.PmsProductManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class PmsProductController {

    @Autowired
    PmsProductManager pmsProductManager;

    //查询商品
    @GetMapping("/product/list")
    public R findProductByPage(@RequestParam(required = false,defaultValue = "1")Integer pageNum,
                               @RequestParam(required = false,defaultValue = "10")Integer pageSize,
                               @RequestParam(required = false)Integer brandId,
                               @RequestParam(required = false)String keyword,
                               @RequestParam(required = false)Integer productCategoryId,
                               @RequestParam(required = false)String productSn,
                               @RequestParam(required = false)Integer publishStatus)
    {
        return pmsProductManager.findProductByPage(pageNum,pageSize,brandId,keyword,productCategoryId,productSn,publishStatus);
    }

    //创建商品
    @PostMapping("/product/create")
    public R createProduct(@RequestBody ProductParam productParam)
    {
        return pmsProductManager.createProduct(productParam);
    }

    //根据商品名称或货号模糊查询
    @GetMapping("/product/simpleList")
    public R findByNameOrId(@RequestParam(required = false)String keyword)
    {
        return pmsProductManager.findByNameOrId(keyword);
    }

    //批量修改删除状态
    @PostMapping("/product/update/deleteStatus")
    public R updateDeleteStatus(Integer [] ids,Integer deleteStatus)
    {
        return pmsProductManager.updateDeleteStatus(ids,deleteStatus);
    }

    //批量设为新品
    @PostMapping("/product/update/newStatus")
    public R setNew(Integer[] ids,Integer newStatus)
    {
        return pmsProductManager.setNew(ids,newStatus);
    }

    //批量上下架商品
    @PostMapping("/product/update/publishStatus")
    public R upAndDown(Integer[] ids,Integer publishStatus)
    {
        return pmsProductManager.upAndDown(ids,publishStatus);

    }

    //批量推荐商品
    @PostMapping("/product/update/recommendStatuss")
    public R recommend(Integer [] ids,Integer recommendStatus)
    {
        return pmsProductManager.recommend(ids,recommendStatus);

    }

    //批量修改审核状态
    @PostMapping("/product/update/verifyStatus")
    public R verify(Integer [] ids,Integer verifyStatus,String detail)
    {
        return pmsProductManager.verify(ids,verifyStatus,detail);

    }

    //更新商品
    @PostMapping("/product/update/{id}")
    public R updateProduct(@PathVariable Integer id,@RequestBody Product productParam)
    {
        return pmsProductManager.updateProduct(id,productParam);
    }

    //根据商品id获取商品编辑信息
    @GetMapping("/product/updateInfo/{id}")
    private R pmsProduct(@PathVariable("id")Integer id){
       return  pmsProductManager.getUpdateMessage(id);

    }


}
